package E2016;

class Result {
    static int[] sum = new int[19];
}
class Addition implements Runnable {
    int sumNumber = 0;
    @Override
    public void run() {
        for (int i = 1; i <= Result.sum.length; i++) {
            int a = i * (i + 1);
            sumNumber = sumNumber + a;
            Result.sum[i - 1] = sumNumber;
            //System.out.println(Result.sum[i-1]);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
class Output implements Runnable {
    @Override
    public void run() {
        for (int i = 1; i <= Result.sum.length; i++) {
            System.out.println("前一个线程的计算结果为：" + Result.sum[i - 1]);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class Exam1 {
    public static void main(String[] args) {
        Thread thread1 = new Thread(new Addition());
        Thread thread2 = new Thread(new Output());
        thread1.start();
        thread2.start();
    }
}
